<template>
	<div class="mask animate__animated animate__fadeIn" v-if="showDialog">
		<div class="box">
			<div class="msg">{{ msg }}</div>
			<div class="btn" v-for="(item, i) in btns" :key="i" @click="doSelect(i)">
				{{ item.text }}
			</div>
		</div>
	</div>
</template>
<script setup>
import { ref, onMounted, watch, nextTick } from "vue";
const showDialog = ref(false);
const msg = ref("");
const btns = ref([]);
const autoClose = ref(true);
const show = (config = {}) => {
	msg.value = config.msg;
	btns.value = config.btns;
	showDialog.value = true;
};
const doSelect = (i) => {
	if (btns.value[i].onclick) {
		btns.value[i].onclick();
		let autoClose = btns.value[i].autoClose ?? true;
		if (autoClose) {
			showDialog.value = false;
		}
	}
};
defineExpose({
	show,
});
</script>
<style scoped>
.mask {
	background: rgb(255 255 255 / 30%);
	position: fixed;
	z-index: 99;
	width: 100vw;
	height: 100vh;
	top: 0;
}
.box {
	background-color: black;
	border-radius: 2vw;
	box-sizing: border-box;
	padding: 3vw;
	width: 60%;
	position: absolute;
	left: 50%;
	top: 50%;
	transform: translate(-50%, -50%);
}
.msg {
	color: white;
	text-align: center;
	font-size: 4vw;
	margin-bottom: 5vw;
}
.btn {
	padding: 0.8vw 5vw;
	border: 2px solid #f1b6b4;
	border-radius: 2px;
	color: transparent;
	-webkit-text-fill-color: #ffffff;
	-webkit-text-stroke: 1px #f1b6b4;
	display: flex;
	justify-content: center;
	align-items: center;
	font-size: 1.5rem;
	box-shadow: 3px 2px 4px 0px #f1b6b4b8;
	user-select: none;
	margin-top: 2vw;
}
</style>
